import axios from 'axios';
import qs from 'query-string';
import type { HttpResponse } from './interceptor';

export interface MultiId {
  id: number;
}

export interface MultiRecord {
  id: number;
  name: string;
  logo: string;
  phone: string;
  account: string;
  created_at: string;
  updated_at: string;
}

export interface MultiListRes {
  list: MultiRecord[];
  total: number;
}

export interface MultiModel {
  id?: number;
  name: string;
  logo?: string;
  phone?: string;
  account: string;
  password?: string;
}

export interface MultiParams extends Partial<MultiRecord> {
  current: number;
  pageSize: number;
}

/**
 * 获取总店列表
 * @param params
 */
export function queryMultiList(params: MultiParams): Promise<HttpResponse<MultiListRes>> {
  return axios.get('/admin/multi/index', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

/**
 * 提交总店表单（创建/更新）
 * @param data
 */
export function submitMultiForm(data: MultiModel): Promise<HttpResponse<MultiRecord>> {
  return axios.post('/admin/multi/submit', data);
}

/**
 * 删除总店
 * @param id
 */
export function delMulti(id: number): Promise<HttpResponse<null>> {
  return axios.post('/admin/multi/delete', { id });
} 

export function getAllMulti(): Promise<HttpResponse<MultiRecord[]>> {
  return axios.get('/admin/multi/all');
}